home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / futilsrc.zoo / fileutil / lib / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-20  |  5.5 KB  |  232 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989-1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. #include <sys/stat.h>
  21. #ifndef S_ISREG            /* Doesn't have POSIX.1 stat stuff. */
  22. #define mode_t unsigned short
  23. #endif
  24. #if !defined(S_ISBLK) && defined(S_IFBLK)
  25. #define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  26. #endif
  27. #if !defined(S_ISCHR) && defined(S_IFCHR)
  28. #define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  29. #endif
  30. #if !defined(S_ISDIR) && defined(S_IFDIR)
  31. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  32. #endif
  33. #if !defined(S_ISREG) && defined(S_IFREG)
  34. #define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  35. #endif
  36. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  37. #define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  38. #endif
  39. #if !defined(S_ISLNK) && defined(S_IFLNK)
  40. #define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  41. #endif
  42. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  43. #define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  44. #endif
  45. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  46. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  47. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  48. #endif
  49. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  50. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  51. #endif
  52. #if defined(MKFIFO_MISSING)
  53. #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0))
  54. #endif
  55.  
  56. #ifdef POSIX
  57. #include <unistd.h>
  58. #include <limits.h>
  59. #ifndef PATH_MAX
  60. #define PATH_MAX pathconf ("/", _PC_PATH_MAX)
  61. #endif
  62. #else
  63. off_t lseek ();
  64. #ifdef USG
  65. #include <sys/times.h>
  66. #else
  67. #include <sys/time.h>
  68. #endif
  69. #ifdef __MINT__
  70. #include <unistd.h>
  71. #include <limits.h>
  72. #endif
  73. #endif
  74.  
  75. #ifndef _POSIX_SOURCE
  76. #include <sys/param.h>
  77. #endif
  78.  
  79. #ifndef _POSIX_PATH_MAX
  80. #define _POSIX_PATH_MAX 255
  81. #endif
  82.  
  83. #ifndef PATH_MAX
  84. #ifdef MAXPATHLEN
  85. #define PATH_MAX MAXPATHLEN
  86. #else
  87. #define PATH_MAX _POSIX_PATH_MAX
  88. #endif
  89. #endif
  90.  
  91. #ifdef _POSIX_SOURCE
  92. #define major(dev)  (((dev) >> 8) & 0xff)
  93. #define minor(dev)  ((dev) & 0xff)
  94. #define makedev(maj, min)  (((maj) << 8) | (min))
  95. #else
  96. #ifdef USG
  97. #ifdef MAJOR_IN_MKDEV
  98. #include <sys/mkdev.h>
  99. #else
  100. #include <sys/sysmacros.h>
  101. #endif
  102. #endif
  103. #endif
  104.  
  105. #ifdef POSIX
  106. #include <utime.h>
  107. #else
  108. #ifndef __MINT__
  109. struct utimbuf
  110. {
  111.   long actime;
  112.   long modtime;
  113. };
  114. #endif
  115. #endif
  116.  
  117. #if defined(USG) || defined(STDC_HEADERS)
  118. #include <string.h>
  119. #define index strchr
  120. #define rindex strrchr
  121. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  122. #define bzero(s, n) memset ((s), 0, (n))
  123. #else
  124. #include <strings.h>
  125. #endif
  126.  
  127. #include <errno.h>
  128. #ifdef STDC_HEADERS
  129. #include <stdlib.h>
  130. #else
  131. char *getenv ();
  132. extern int errno;
  133. #endif
  134.  
  135. #if defined(USG) || defined(POSIX)
  136. #include <fcntl.h>
  137. char *getcwd ();
  138. #define getwd(buf) getcwd ((buf), PATH_MAX + 2)
  139. #else
  140. #include <sys/file.h>
  141. char *getwd ();
  142. #endif
  143.  
  144. #ifndef SEEK_SET
  145. #define SEEK_SET 0
  146. #define SEEK_CUR 1
  147. #define SEEK_END 2
  148. #endif
  149. #ifndef F_OK
  150. #define F_OK 0
  151. #define X_OK 1
  152. #define W_OK 2
  153. #define R_OK 4
  154. #endif
  155.  
  156. #ifdef DIRENT
  157. #include <dirent.h>
  158. #ifdef direct
  159. #undef direct
  160. #endif
  161. #define direct dirent
  162. #define NLENGTH(direct) (strlen((direct)->d_name))
  163. #else
  164. #define NLENGTH(direct) ((direct)->d_namlen)
  165. #ifdef USG
  166. #ifdef SYSNDIR
  167. #include <sys/ndir.h>
  168. #else
  169. #include <ndir.h>
  170. #endif
  171. #else /* must be BSD */
  172. #include <sys/dir.h>
  173. #endif
  174. #endif
  175.  
  176. #ifdef VOID_CLOSEDIR
  177. /* Fake a return value. */
  178. #define CLOSEDIR(d) (closedir (d), 0)
  179. #else
  180. #define CLOSEDIR(d) closedir (d)
  181. #endif
  182.  
  183. /* Extract or fake data from a `struct stat'.
  184.    ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes.
  185.    ST_NBLOCKS: Number of 512-byte blocks in the file
  186.    (including indirect blocks). */
  187. #ifdef _POSIX_SOURCE
  188. #define ST_BLKSIZE(statbuf) 1024
  189. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512)
  190. #else
  191. #ifdef ST_BLOCKS_MISSING
  192. #define ST_BLKSIZE(statbuf) BSIZE
  193. #define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  194. #else
  195. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  196. #define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  197.                  ? (statbuf).st_blksize : DEV_BSIZE)
  198. #if defined(hpux) || defined(__hpux__)
  199. /* HP-UX, perhaps uniquely, counts st_blocks in 1024-byte units.
  200.    This loses when mixing HP-UX and 4BSD filesystems, though. */
  201. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2)
  202. #else
  203. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  204. #endif
  205. #endif
  206. #endif
  207.  
  208. /* Convert B 512-byte blocks to kilobytes if K is nonzero,
  209.    otherwise return it unchanged. */
  210. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  211.  
  212. #ifndef S_ISLNK
  213. #define lstat stat
  214. #endif
  215.  
  216. #ifndef SIGTYPE
  217. #define SIGTYPE void
  218. #endif
  219.  
  220. #ifdef __GNUC__
  221. #define alloca __builtin_alloca
  222. #else
  223. #ifdef sparc
  224. #include <alloca.h>
  225. #else
  226. #ifndef _AIX
  227. /* AIX alloca decl has to be the first thing in the file, bletch! */
  228. char *alloca ();
  229. #endif
  230. #endif
  231. #endif
  232.